import csv

import requests as rq
from pyquery import PyQuery as pq
from selenium import  webdriver
from selenium.webdriver.support.wait import WebDriverWait
from  selenium.webdriver.chrome.options import Options
url = 'https://voice.baidu.com/act/newpneumonia/newpneumonia/?from=osari_aladin_banner#tab4'
chrome_options = Options()
browser = webdriver.Chrome()
chrome_options = Options()
chrome_options.add_argument('--headless')
browser = webdriver.Chrome(chrome_options=chrome_options)

def get_html(url):
    browser.get(url)
    html = browser.page_source
    # with open(r'tes1.html', 'w+', encoding='utf-8') as f:
    #     f.write(html)
    return html


def get_date():
    datas = browser.find_elements_by_xpath('//*[@id="nationTable"]/table/tbody/tr')
    return datas

def data_write(datas):
    f = open(r'test.csv', 'w')
    with f:
        w = csv.writer(f)
        for data in datas:
            w.writerow(data.text)

if __name__ == '__main__':
    html = get_html(url)
    data_write(get_date())